package com.tduck.cloud.api.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tduck.cloud.api.web.ao.ScoreLevelAO;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.form.entity.ScoreLevelEntity;
import com.tduck.cloud.form.service.ScoreLevelService;
import com.tduck.cloud.form.vo.ScoreLevelVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/score-level")
@RequiredArgsConstructor
public class ScoreLevelController {
    private final ScoreLevelService scoreLevelService;
    private final ScoreLevelAO scoreLevelAO;

    @GetMapping("/page/{formKey}")
    public Result<Page<ScoreLevelEntity>> page(Page page, @PathVariable String formKey) {
        QueryWrapper<ScoreLevelEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("form_key",formKey);
        return Result.success(scoreLevelService.page(page,queryWrapper));
    }

    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody ScoreLevelVO scoreLevelVO) {
        return Result.success(scoreLevelAO.save(scoreLevelVO));
    }

    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(scoreLevelService.removeById(id));
    }


}
